package com.tubruk.adapter;

import java.io.File;
import java.util.ArrayList;

import com.tubruk.object.FileWrapper;
import com.tubruk.trackme.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FileAdapter extends ArrayAdapter<FileWrapper> {
	private ArrayList<FileWrapper> items;
	private LayoutInflater vi;
	

	public FileAdapter(Context context, int textViewResourceId,
			ArrayList<FileWrapper> items) {
		super(context, textViewResourceId, items);
		this.items = items;
        vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        
	}

	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
	
		FileWrapper item = items.get(position);
		
		if (v == null){
			v = vi.inflate(R.layout.file_row, null);
		}
		
		ImageView dir = (ImageView) v.findViewById(R.id.browse);
		if (item.isDirectory()){
			dir.setVisibility(View.VISIBLE);
		}else {
			dir.setVisibility(View.INVISIBLE);
		}
		
		TextView tv = (TextView) v.findViewById(R.id.title);
		tv.setText(item.getName());
		
		
		return v;
	}
}
